<template>
	<view class="main">
		<!-- <view class="msg_list" @click="list(item.id)" v-for="(item,index) in msgs" :key="index">
		<view class="msg_list_tit"><text class="t22">{{item.title}}</text><text class="t1">{{item.addtime}}</text></view>
		</view> -->
		<view class="msg_list" v-for="(item,index) in msgs" :key="index">
			<view class="msg_list_tit"><text class="t22">{{item.title}}</text><text class="t1">{{item.content}}</text>
			</view>
			<view class="msg_list_time t24">{{item.createdTime}}</view>
		</view>
		<view class="zanwu" v-show="jiazai" style="padding-top: 4vw;margin-bottom: 10vw;"><text
				class="t7">{{more}}</text></view>
		<view class="zanwu" v-show="zanwu" style="margin-bottom: 10vw;">
			<image src="../../static/img/zanwu.png" mode="widthFix"></image><text class="t8">{{wu}}</text>
		</view>
		<!-- <view class="msg_list" @click="list(1)">
		<view class="msg_list_tit"><text class="t22">公告标题</text><text class="t1">公告标详情公告标详情公告标详情公告标详情公告标详情</text></view>
		<view class="msg_list_time t14">2020<br>04/25</view>
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				msgs: [],
				pages: 1,
				ismore: true,
				more: '加载更多',
				jiazai: false,
				wu: "暂无数据",
				zanwu: false,
			}
		},
		// 监听触底
		onReachBottom() {
			//阻止重复加载
			if (this.ismore == false) {
				return;
			}
			this.pages++;
			this.messgaelist();

		},
		onLoad() {
			this.messgaelist();
		},
		methods: {

			list(e) {
				// console.log(e);
				uni.navigateTo({
					url: '/pages/msg/msg?id=' + e
				});
			},
			// messgaelist() {
			// 	uni.request({
			// 		header: {
			// 			'Content-Type': 'application/json', //自定义请求头信息
			// 		},
			// 		url: getApp().globalData.url + 'article/bulletinList', //仅为示例，并非真实接口地址。
			// 		method: 'POST',
			// 		// data: {
			// 		// 	limitNum: 10,
			// 		// },
			// 		success: (res) => {
			// 			uni.hideLoading(); //关闭加载动画
			// 			this.checks = true
			// 			console.log(res);
			// 			if (res.data.status == '200') {
			// 				this.msgs = res.data.data;
			// 			} else {}
			// 		},
			// 		fail: (error) => {
			// 			// console.log(error)
			// 		}
			// 	});
			// },
			messgaelist() {
				uni.request({
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
					},
					url: getApp().globalData.url + 'article/bulletinList', //仅为示例，并非真实接口地址。
					method: 'POST',
					// data: {
					// 	limitNum: 10,
					// },
					success: (res) => {
						uni.hideLoading(); //关闭加载动画
						if (res.data.status == '200') {

							if (res.data.data.length == 0 && this.pages != 1) {
								this.more = "没有更多数据了";
								this.jiazai = true;
								this.zanwu = false;
								this.ismore = false;
							} else if (res.data.data.length == 0 && this.pages == 1) {
								this.more = "暂无数据";
								this.jiazai = false;
								this.zanwu = true;
								this.ismore = false;
							} else if (res.data.data.length < 10) {
								this.jiazai = true;
								this.zanwu = false;
								this.ismore = false;
								this.more = "没有更多数据了";
							} else {
								this.more = "暂无数据";
								this.jiazai = true;
								this.zanwu = false;
								this.ismore = true;
							}
							if (this.pages == 1) {
								this.msgs=[];
								for (var i = 0; i < res.data.data.length; i++) {
									if (res.data.data[i].type == '1') {
										this.msgs.push(res.data.data[i]);
									}
								}
							} else {
								for (var i = 0; i < res.data.data.length; i++) {
									if (res.data.data[i].type == 1) {
										this.msgs.push(res.data.data[i]);
									}
								}
							}
						}
					},
					fail: (error) => {
						uni.hideLoading();
						// this.checks = true
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
						console.log(error)
					}
				});
			},
		}
	}
</script>

<style>
	.msg_list {
		width: 100%;
		height: auto;
		display: block;
		float: left;
		/* box-shadow: 0px 0px 5px #F2F2F2; */
		padding: 2vw 3vw;
		border-radius: 2vw;
		/* border: 1px solid #F2F2F2; */
		margin-top: 4vw;
		background: #fff;
	}

	.msg_list_tit {
		width: 100%;
		height: auto;
		display: block;
		float: left;
		padding: 1vw 0;
		/* line-height: 7vw; */
	}

	.msg_list_tit text {
		width: 100%;
		height: auto;
		line-height: 6vw;
		 padding: 2vw 0;
		display: block;
		float: left;
		overflow: hidden;
	}

	.about_info {
		width: 100%;
		height: auto;
		display: block;
		float: left;
		line-height: 6vw;
	}

	.msg_list_time {
		width: 100%;
		height: auto;
		display: block;
		float: right;
		text-align: right;
		line-height: 6vw;
		margin-top: 1vw;
	}
</style>
